<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      function getMoney(list = []) {
        if (list.length === 0) return 0
        if (list.length === 1) return list[0]
     
        const dp = [list[0], Math.max(list[0], list[1])]
        for (let i = 2; i < list.length; i++) {
          dp[i] = Math.max(list[i] + dp[i - 2], dp[i - 1])
        }
        return dp[dp.length - 1]
      }
      console.log(getMoney([2,7,9,3,1]))
    </script>
  </body>
</html>
